<template>
    <div>
        <el-form ref="form" :model="form" label-width="120px" class="form" slot="main">
            <el-form-item label="知识库的类别">
                <el-radio-group v-model="form.type">
                <el-radio label="文档知识库"></el-radio>
                <el-radio label="表格知识库"></el-radio>
                <el-radio label="资源知识库"></el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="文档名称">
                <el-input type="text" v-model="form.name"></el-input>
            </el-form-item> 
        </el-form>
        <div ref="editor" style="text-align:left"></div>
        <el-button @click="saveText">保存</el-button>
    </div>
</template>
<script>
    import E from 'wangeditor'
    export default {
      name: 'editor',
      data () {
        return {
          editorContent: '',
          form: {
            type: '文档知识库',
            name: '',
          }
        }
      },
      methods: {
        saveText() {
          const textContent = this.editorContent // 要存到数据库中的文档
          this.$axios.post('/api/doc/add', {
            text: textContent,
            type: this.form.type,
            name: this.form.name,
          }).then(res => {
            if (res.data.code === 1) {
              this.$router.push('/document/list')
            } else {
              alert(res.data.msg)
            }
          })
        },
        getContent: function () {
            alert(this.editorContent)
        }
      },
      mounted() {
        var editor = new E(this.$refs.editor)
        editor.customConfig.onchange = (html) => {
          this.editorContent = html
        }
        editor.create()
      }
    }
</script>
<style scoped>
</style>
